<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript">

    $().ready(function() {
        view();

         /* 저장버튼 */
        $("#saveBtn").bind("click",function(){       
            $("form[name='productUpdateFrm']").submit();
        });

        $("#onList").bind("click",function(){
            location="/product.html";            
        });
        
        $("#customerPopup").bind("click",function(){
            onCustomerPopup();
            
        });

        /* 메인폼 서브밋 */
        $("form[name='productUpdateFrm']").ajaxForm({
            dataType: "json",
            beforeSerialize: function($form, options) {
                //return $("form[name='orderFrm']").valid();  jquery 벨류데이션 플러그인 사용시
                 if( !validation() ){       //화면 항목 점검 시작
                    return false;
                }
            },
            success:function(data) {
               if(data.result == true){
                   alert("Saved.....!");
                   location="/product.html";    
               }               
           },
           error:function(){alert("ERROR!");}
        }); 
    });

    /* 조회 펑션 */
    function view(){
        $.post(
                '/getProductDetailView.json', {
                goodsCode : $("#goodsCode").val()
                },
            function(data) {
                //reSetValidete(); //벨류데이션 초기화
                
                searchDataMaping(data);    //DATA맵핑 
            });
    }

    /* searchData 맵핑 */
    function searchDataMaping(data){
        var val = ""; 
        for(var v in data.resultDetailMap) {       //상단 조회 결과 맵핑 조회return값이 한건임
            $("#"+v).val(data.resultDetailMap[v]);
        }        
    }

    function validation(){

    	var goodsName       = $("#goodsName").val();
        var unit            = $("#unit").val();
        var boxQty          = $("#boxQty").val();
        var hsCode          = $("#hsCode").val();
        var custCode        = $("#custCode").val();
        var productCode     = $("#productCode").val();
        
        if(goodsName==null   || goodsName=="") {   alert("Product Name required!!"); $("#goodsName").focus(); return false; }
        if(unit==null        || unit=="") { alert("Unit required!!"); $("#unit").focus(); return false; }
        if(boxQty==null      || boxQty=="") { alert("Box required!!"); $("#boxQty").focus(); return false; }
        if(hsCode==null      || hsCode=="") { alert("H.S Code required!!"); $("#hsCode").focus(); return false; }
        if(custCode==null    || custCode=="") { alert("Shipper required!!"); $("#custCode").focus(); return false; }
        if(productCode==null || productCode=="") { alert("Product Code required!!"); $("#productCode").focus(); return false; }
   
      return true;      
    } 
    
    function onCustomerPopup(){
        window.open('/customerPop.html?customer=2', 'changeProductPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }
    
    function customerPopValue(arg, arg1){
        $("#custCode").val(arg);
        $("#custName").val(arg1);        
    }
    
</script>
</head>
<body>
<div class="wrap">
    <form name="productUpdateFrm" method="post" action="/saveProduct.json">
    <div class="pagetitle">
        <h1>PRODUCT / UPDATE</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th>Product</th>
                <td><input type="text" class="inST" size="80" name="goodsName" id="goodsName"/>
                </td>
                
            </tr>
            <tr>
                <th>Unit</th>
                <td><input type="text" class="inST" size="80" name="unit" id="unit"/></td>
            </tr>
            <tr>
                <th>Box</th>
                <td><input type="text" class="inST" size="80" name="boxQty" id="boxQty"/></td>
            </tr>
            <tr>
                <th>H.S Code</th>
                <td><input type="text" class="inST" size="80" name="hsCode" id="hsCode"/></td>
            </tr>
            <tr>
                <th>Messrs</th>
                <td>
                    <input type="text" class="inSTR" size="80" name="custName" id="custName" readonly/>
                    <a href="#"><img src="images/web/bkn_zoom.gif" alt="customerPopup" id="customerPopup"/></a>
                    <input type="hidden" class="inST" size="80" name="custCode" id="custCode"/>
                </td>
            </tr>
            <tr>
                <th>Product Code</th>
                <td>
                    <input type="text" class="inST" size="80" name="productCode" id="productCode"/>
                    <!-- textarea class="teST" wrap="virtual" name="productCode" id="productCode"></textarea-->
                </td>
            </tr>
            
         </table>
    </div>
    <div class="bo_btn">
        <ul class="btnst"><li class="a"><a href="#" id="onList" >LIST</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="saveBtn" >SAVE</a></li></ul>
    </div>
    <input type="hidden" name="goodsCode" id="goodsCode" value="${goodsCode}"/>
    <input type="hidden" name="saveStatus" id="saveStatus" value="UPDATE"/>
    </form>
</div>
</body>
</html>